package com.firexxx.vp.infrastructure.file;

import com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: TODO
 * @throws:
 * @author: zhuangzhang2
 * @date: 2019/12/27 15:11
 */
@Service
public class FastDFSClientWrapper implements InitializingBean {

    @Autowired
    private FastFileStorageClient storageClient;

    public byte[] download(String fileUrl) {
        String group = fileUrl.substring(0, fileUrl.indexOf("/"));
        String path = fileUrl.substring(fileUrl.indexOf("/") + 1);
        DownloadByteArray downloadByteArray = new DownloadByteArray();
        return storageClient.downloadFile(group, path, downloadByteArray);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
//        AudioStorage.fastDFSClientWrapper = this;
    }
}